package com.doubao.file.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.doubao.file.entity.FileInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 文件信息Mapper
 */
@Mapper
public interface FileInfoMapper extends BaseMapper<FileInfo> {

    /**
     * 根据用户ID和聊天ID查询文件信息
     */
    @Select("SELECT * FROM file_info WHERE user_id = #{userId} AND chat_id = #{chatId} AND status = 1 ORDER BY created_at DESC")
    List<FileInfo> selectByChatId(@Param("userId") Long userId, @Param("chatId") String chatId);

    /**
     * 根据用户ID查询文件信息
     */
    @Select("SELECT * FROM file_info WHERE user_id = #{userId} AND file_type = #{fileType} AND status = 1 ORDER BY created_at DESC")
    List<FileInfo> selectByUserIdAndType(@Param("userId") Long userId, @Param("fileType") Integer fileType);

    /**
     * 查询用户最新的头像
     */
    @Select("SELECT * FROM file_info WHERE user_id = #{userId} AND file_type = 1 AND status = 1 ORDER BY created_at DESC LIMIT 1")
    FileInfo selectLatestAvatar(@Param("userId") Long userId);
}